package com.heqiang.spring;

import com.heqiang.spring.config.BeanDefinition;
import com.heqiang.spring.factory.DefaultListableBeanFactory;
import com.heqiang.spring.service.TestService;

import java.lang.reflect.Constructor;


/**
 * 学习链接
 * https://mp.weixin.qq.com/s/olrwapkSTQMyIGpR10ZDzA
 */
public class TestMain {

    public static void main(String[] args) {
        //创建工厂
        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
        //注册bean
        BeanDefinition beanDefinition = new BeanDefinition(TestService.class);
        beanFactory.registerBeanDefinition("testService",beanDefinition);
        //获取bean
        TestService testService = (TestService) beanFactory.getBean("testService","heqiang");
        testService.getInfo();

    }


    public static void main2(String[] args) throws Exception {
        Class<TestService> serviceClass = TestService.class;
        Constructor<TestService> declaredConstructor = serviceClass.getDeclaredConstructor(String.class);
        TestService testService = declaredConstructor.newInstance("heqiang");
        System.out.println(testService);
    }
}
